//
//  Memery.m
//  Aop
//
//  Created by JYHeguang on 2023/11/22.
//

#import "Memery.h"
#import <Storage/Storage.h>

@interface Memery ()

@property (nonatomic, strong) id<IStorage> storage;
@end

@implementation Memery

+ (nonnull id<IMemery>)shareInstance {
    static Memery *__shareInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        __shareInstance = [[Memery alloc] init];
    });
    return __shareInstance;
}

+ (nonnull id<IStorage>)storageOf:(nonnull StorageType)storageType {
    return [self.shareInstance storageOf:storageType];
}

- (nonnull id<IStorage>)storageOf:(nonnull StorageType)storageType {
    id target = [self.storage get:storageType];
    if (!target) {
        target = [[Storage alloc] init];
        [self.storage create:target key:storageType];
    }
    return target;
}

- (id<IStorage>)storage{
    if (!_storage) {
        _storage = (id<IStorage>)[[Storage alloc] init];
    }
    return _storage;
}
@end
